package com.bluecc.sqlflow.phoenix;

import java.sql.*;
public class PhoenixProcs {
    public static Connection getConn() {
        Connection conn = null;
        try {
            Class.forName("org.apache.phoenix.queryserver.client.Driver");
            conn = DriverManager.getConnection("jdbc:phoenix:thin:url=http://localhost:8765/PHOENIX;serialization=PROTOBUF", "lucky", "pratama");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Cannot find driver");
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        return conn;
    }

    public static void main(String[] args) {

        Connection conn;
        Statement st;
        ResultSet rs;

        try {
            conn = getConn();
            st = conn.createStatement();
            String sql;
            sql = "SELECT * FROM users";
            rs = st.executeQuery(sql);

            while (rs.next()) {
                int symbol = rs.getInt(1);
                String name = rs.getString(2);
                System.out.println("User Symbol: "+symbol + "\nName     : " + name+"\n");
            }

            rs.close();
            st.close();
            conn.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

